//
//  CTUserFavoriteCell.m
//  ConstellationTalk_0.1
//
//  Created by 韩威 on 15/5/25.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTUserFavoriteCell.h"
#import "CTRequestUtil.h"
#import "CTDebugManager.h"
#import "UIViewAdditions.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"

@interface CTUserFavoriteCell()
{
    UIImageView        *picImageView;
    UILabel            * nameLabel;
    UILabel            * countLabel;
    UIImageView        * trendsImageView;
    UIImageView        * originImageView;
    UIImageView        * describeImageView;
    
    UIButton           * moreBtn;
    
    UILabel * trendsLabel;
    UILabel * originLabel;
    UILabel * describeLabel;

}

@end

@implementation CTUserFavoriteCell
@synthesize delegate;
- (void)dealloc
{
    [picImageView removeFromSuperview];
    picImageView = nil;
    [nameLabel removeFromSuperview];
    nameLabel = nil;
    [countLabel removeFromSuperview];
    countLabel = nil;
    [trendsImageView removeFromSuperview];
    trendsImageView = nil;
    [originImageView removeFromSuperview];
    originImageView = nil;
    [describeImageView removeFromSuperview];
    describeImageView = nil;
    [moreBtn removeFromSuperview];
    moreBtn = nil;
    
    [trendsLabel removeFromSuperview ];
    trendsLabel = nil;
    [originLabel removeFromSuperview];
    originLabel  = nil;
    [describeLabel removeFromSuperview];
    describeLabel = nil;
    
    [CTDebugManager showErrorLogInfo:@"dealloc : CTUserFavoriteCell Is Removed!!!!"];

}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor greenColor];
        [self awakeFromNib];
    }
    return self;
}
- (void)awakeFromNib
{
    picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 118, 75)];
    picImageView.layer.cornerRadius = 3;
    picImageView.layer.masksToBounds = YES;
    picImageView.backgroundColor = [UIColor redColor];
    [self addSubview:picImageView];
    
    
    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(picImageView.right+10, 20, CT_HEADER_SCREEN_WIDTH-20-picImageView.width, 15)];
    nameLabel.font = [UIFont systemFontOfSize:15];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0  blue:246/255.0  alpha:1.0];
    [self addSubview:nameLabel];
    
    
    trendsImageView = [[UIImageView alloc] initWithFrame:CGRectMake(picImageView.right+10, nameLabel.bottom+10, 38, 18)];
//    trendsImageView.image = [UIImage imageNamed:@"tag_one"];
    trendsImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:trendsImageView];
    
    originImageView = [[UIImageView alloc] initWithFrame:CGRectMake(trendsImageView.right+10,nameLabel.bottom+10, 38, 18)];
    originImageView.image = [UIImage imageNamed:@"tag_two"];
    originImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:originImageView];
    
    
    describeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(originImageView.right+10,nameLabel.bottom+10, 58, 18)];
    describeImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:describeImageView];
    
    
    trendsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 38, 18)];
    trendsLabel.font = [UIFont systemFontOfSize:14];
    trendsLabel.textAlignment = NSTextAlignmentCenter;
    trendsLabel.textColor = [UIColor colorWithRed:254/255.0 green:182/255.0 blue:130/255.0 alpha:1.0];
    [trendsImageView addSubview:trendsLabel];
    
    originLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 38, 18)];
    originLabel.font = [UIFont systemFontOfSize:14];
    originLabel.textAlignment = NSTextAlignmentCenter;
    originLabel.textColor = [UIColor colorWithRed:163/255.0 green:227/255.0 blue:216/255.0 alpha:1.0];
    [originImageView addSubview:originLabel];
    
    describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 58, 18)];
    describeLabel.font = [UIFont systemFontOfSize:14];
    describeLabel.textAlignment = NSTextAlignmentCenter;
    describeLabel.textColor = [UIColor colorWithRed:255/255.0 green:225/255.0 blue:114/255.0 alpha:1.0];
    [describeImageView addSubview:describeLabel];
    
    countLabel = [[UILabel alloc] initWithFrame:CGRectMake(picImageView.right+10, trendsImageView.bottom+10, nameLabel.width, 15)];
    countLabel.font = [UIFont systemFontOfSize:15];
    countLabel.backgroundColor = [UIColor redColor];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.textColor = [UIColor colorWithRed:254/255.0 green:182/255.0 blue:130/255.0 alpha:1.0];
    [self addSubview:countLabel];
    
    moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    moreBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-10-25, (105-25)/2, 25, 25);
    [moreBtn setBackgroundImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
    [moreBtn setBackgroundImage:[UIImage imageNamed:@"more_click"] forState:UIControlStateHighlighted];
    [moreBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:moreBtn];
    
    UILabel *bottomLine = [[UILabel alloc]initWithFrame:CGRectMake(10, 104.5, CT_HEADER_SCREEN_WIDTH-20, 0.5)];
    bottomLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:bottomLine];
}

- (void)moreBtnAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(userFavoriteCellMoreBtn:)])
    {
        [self.delegate userFavoriteCellMoreBtn:self];
    }
}

#pragma mark - setter -

-(void)setImgUrl:(NSString *)imgUrl
{
    [CTRequestUtil requestImgWithUrl:imgUrl withCompletionSuccessHandler:^(UIImage *img) {
        picImageView.image = img;
    } withFailedHandler:^(NSError *error) {
        
    }];
}
-(void)setDescribe:(NSString *)describe
{
    describeLabel.text = describe;
    if (describeLabel.text.length == 3)
    {
        describeImageView.image = [UIImage imageNamed:@"tag_three"];
    }
    else
    {
        describeImageView.image = [UIImage imageNamed:@"tag_three_short"];
    }
}
-(void)setName:(NSString *)name
{
    nameLabel.text = name;
}
-(void)setOrigin:(BOOL)isOfficial
{
    if (isOfficial == YES) {
        originImageView.hidden = NO;
        originLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_offical" withValue:nil withTable:@"Language"];
        
        describeImageView.frame = CGRectMake( originImageView.frame.size.width+trendsImageView.frame.size.width+20,140, 58, 18);
        if (originLabel.text.length == 3)
        {
            originImageView.image = [UIImage imageNamed:@"tag_two"];
        }
        else
        {
            originImageView.image = [UIImage imageNamed:@"tag_two_short"];
        }
    }else{
        originImageView.hidden = YES;
        
        describeImageView.frame = CGRectMake(trendsImageView.frame.size.width+10,140, 58, 18);
    }
}
-(void)setTrends:(BOOL)isTrends
{
    if (isTrends == YES) {
        trendsLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_dynamic" withValue:nil withTable:@"Language"];
        
    }else{
        trendsLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_static" withValue:nil withTable:@"Language"];
    }
    if (trendsLabel.text.length ==3)
    {
        trendsImageView.image = [UIImage imageNamed:@"tag_one"];
    }
    else
    {
        trendsImageView.image = [UIImage imageNamed:@"tag_one_short"];
    }
}
#pragma mark - main thread -

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
